<template>
  <BasicModal
    v-bind="$attrs"
    :title="t('routes.demo.PartAndDrawingSettings.inboundSetting')"
    @register="register"
    @ok="handleSubmit"
    :destroyOnClose="true"
    :minHeight="100"
    :width="600"
  >
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>

<script lang="ts" setup>
  import { useI18n } from '/@/hooks/web/useI18n';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { getInboundSettingModalForm } from './data';

  import { updatePartDocTypeListAndInStore } from '/@/api/demo/system';

  const { t } = useI18n();
  const { createMessage } = useMessage();

  // 提交
  const handleSubmit = async () => {
    try {
      setModalProps({ confirmLoading: true });
      const res = await updatePartDocTypeListAndInStore(getFieldsValue().rkOption);
      if (res) {
        createMessage.success(t('common.saveSuccess'));
        closeModal();
      }
    } finally {
      setModalProps({ confirmLoading: false });
    }
  };

  // 初始化弹窗
  const [register, { setModalProps, closeModal }] = useModalInner((data) => {
    setModalProps({ confirmLoading: false });
    setFieldsValue(data);
  });

  // 属性详情
  const [registerForm, { setFieldsValue, getFieldsValue }] = useForm({
    labelCol: { span: 6 },
    wrapperCol: { span: 16 },
    schemas: getInboundSettingModalForm(),
    showResetButton: false,
    showSubmitButton: false,
  });
</script>
